Passed
Pull Request — master (#17)
by
unknown
57s
created

actions.createTask   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
/* eslint-env webextensions */
2
3
function encodeTaskProperties(omnifocusTask) {
4
  return {
5
    name: encodeURIComponent(omnifocusTask.name),
6
    note: encodeURIComponent(omnifocusTask.note),
7
  };
8
}
9
10
const senders = {
11
  app(config, encodedTask) {
12
    return `omnifocus:///add?name=${encodedTask.name}&note=${encodedTask.note}`;
13
  },
14
  maildrop(config, encodedTask) {
15
    return `mailto:${config.address}@sync.omnigroup.com?subject=${encodedTask.name}&body=${encodedTask.note}`;
16
  },
17
};
18
19
const actions = {
20
  createTask(taskInfo) {
21
    const sender = localStorage.sender || 'app';
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
22
    const encodedTask = encodeTaskProperties(taskInfo);
23
24
    return {
25
      url: senders[sender](localStorage, encodedTask),
26
    };
27
  },
28
};
29
30
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
0 ignored issues
show
Bug introduced by
The variable chrome seems to be never declared. If this is a global, consider adding a /** global: chrome */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
31
  let responseData = false;
32
33
  if (actions[request.method]) {
34
    responseData = actions[request.method](request.params);
35
  }
36
37
  sendResponse(responseData);
38
});
39